﻿<!DOCTYPE html>
<html>
<!-- 培训课程管理 -->

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

</head>

<body>
    <div id="app" class="popupW50" v-cloak>
        <el-form label-position="right" :model="Form" status-icon :rules="rules" ref="ruleForm" label-width="100px"
            size="mini">
            <el-row>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <label class="el-form-item__label"></label>
                        <label class="fl" style="margin: 10px 10px 0 0;">{{Form.FileList}}</label>
                        <el-upload class="fl" ref="Attachmentupload" action="/api/File/UpdateFile" multiple="true"
                            :on-preview="handlePreview" :on-remove="handleRemove"
                            :before-upload="CoursewareUploadbeforeupload" :auto-upload="true" :limit="1"
                            :show-file-list="false">
                            <el-button style="margin: 10px;" type="primary" size="mini" @click="btnFileListUpload">
                                {{col.lawUploadLabel}}
                            </el-button>
                        </el-upload>
                    </div>
                </el-col>
                <!--<el-col :span="24">
                    <div class="elst-select-mini">
                        <label class="el-form-item__label">{{LawRegulationStandardSpecification.Attachment+mark.m}}</label>
                        <label class="fl" style="margin: 10px 10px 0 0;">{{Form.Attachment}}</label>
                        <el-upload class="fl" ref="Attachmentupload" action="/api/File/UpdateFile" multiple="true"
                            :on-preview="handlePreview" :on-remove="handleRemove"
                            :before-upload="CoursewareUploadbeforeupload2" :auto-upload="true" :limit="1"
                            :show-file-list="false">
                            <el-button style="margin: 10px;" type="primary" size="mini" @click="btnAttachmentUpload">
                                {{col.lawUploadAttachment}}
                            </el-button>
                        </el-upload>
                    </div>
                </el-col>-->
            </el-row>
            <el-row type="flex" justify="end">
                <el-form-item>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSave}}</el-button>
                    <!--<el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnCommit}}</el-button>-->
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                </el-form-item>
            </el-row>
        </el-form>
    </div>
    <script type="text/javascript">
        var uploadText = "请选择上传Excel文件";
        var uploadText2 = "请选择上传附件";
        var app = new Vue({
            el: '#app',
            data: {
                //父业传参
                id: '',
                imageUrl: '',
                checked: true,
                value1: '',
                radio: '1',
                ListItem: ListItem,
                formInline: {
                    model: {
                        FileList: '',
                        Attachment: '',
                    },
                    offset: 0,
                    limit: 10
                },
                //业务表单内容
                Form: {
                    id: guidEmpty,
                    FileList: uploadText,
                    Attachment: uploadText2,


                },
                //表单验证
                rules: {
                }
            },

            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                handleRemove: function (file) {
                    console.log(file);
                },
                handlePreview: function (file) {
                    console.log(file.name);
                    window.open(file.url)
                },
                //上传附件文件的校验
                CoursewareUploadbeforeupload: function (file) {
                    var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
                    //将附件名赋值到label上
                    this.Form.FileList = file.name;
                    const extension = testmsg === 'xlsx'
                    const isLt10M = file.size / 1024 / 1024 < 10
                    if (!extension) {
                        this.$message({
                            message: '上传文件只能是excel格式!',
                            type: 'warning'
                        });
                    }
                    if (!isLt10M) {
                        this.$message({
                            message: '上传文件大小不能超过 10MB!',
                            type: 'warning'
                        });
                    }
                    if (extension || extension2 && isLt10M)
                        submitUpload(this, 'upload')
                    return extension || extension2 && isLt10M
                },
                CoursewareUploadbeforeupload2: function (file) {
                    var testmsg = file.name.substring(file.name.lastIndexOf('.') + 1)
                    //将附件名赋值到label上
                    this.Form.Attachment = file.name;
                    const extension = testmsg === 'doc'
                    const extension2 = testmsg === 'pdf'
                    const isLt10M = file.size / 1024 / 1024 < 10
                    if (!extension && !extension2) {
                        this.$message({
                            message: '上传文件只能是 doc、pdf格式!',
                            type: 'warning'
                        });
                    }
                    if (!isLt10M) {
                        this.$message({
                            message: '上传文件大小不能超过 10MB!',
                            type: 'warning'
                        });
                    }
                    if (extension || extension2 && isLt10M)
                        submitUpload(this, 'upload')
                    return extension || extension2 && isLt10M
                },
                btnFileListUpload: function () {
                    //若更换文件则将文件名字更换触发条件--先删除上一个文件,后添加一个文件
                    if (this.fileAttachmentUpload != uploadText) {
                        this.$refs.Attachmentupload.clearFiles();
                        this.fileAttachmentUpload = file.name;
                    }
                    else {

                    }
                    this.$refs.Attachmentupload.submit();
                },
                btnAttachmentUpload: function () {
                    //若更换文件则将文件名字更换触发条件--先删除上一个文件,后添加一个文件
                    if (this.fileAttachmentUpload != uploadText2) {
                        this.$refs.Attachmentupload.clearFiles();
                        this.fileAttachmentUpload = file.name;
                    }
                    else {

                    }
                    this.$refs.Attachmentupload.submit();
                },
                //查询方法
                onSubmit: function () {
                    onSubmit(this);
                },
                btnUpLoad: function () {
                    this.$message({
                        message: '上传成功',
                        type: 'success'
                    });
                },
                //提交数据
                onSubmitForm: function (formName) {
                    this.Form.Encryptionornot = this.Form.Encryptionornot.toString();
                    var mythis = this;
                    this.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            onSubmitForm(this, '/api/FL_StandardInformationWeb/Import', mythis.Form);
                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                getData: function () {
                    getData(this, '/api/LawRegulationsUpdate/get?id=' + this.id);
                },

                //删除方法
                onDelete: function () { onDelete(this, '/api/LawRegulationsUpdate/DeleteMuti'); },
                //列表选择触发
                UserInputStatistics: function (val, id) { DialogShow(this, val, "LawRegulationsUpdate.html", id); },
                handleSelectionChange: function (val) { handleSelectionChange(this, val); },
                //获取分页数据
                GetPageData: function (currentIndex) { GetPageData(this, currentIndex, '/api/LawRegulationsUpdate/GetList') },
                //pagesize改变 触发方法
                handleSizeChange: function (val) { handleSizeChange(this, val); },
                //跳页触发方法
                handleCurrentChange: function (val) { handleCurrentChange(this, val); },
                addTrainer: function (val, id) {
                    DialogShow(this, val, "TrainingPlanManagementluruInputTrainer.html", id);
                },
            },
            updated: function () {
                this.Form.Encryptionornot = eval(this.Form.Encryptionornot.toLowerCase());
            },
            mounted: function () {
                //初始化数据
                this.GetPageData(1);
                //列表高度自适应
                tablehigh(this);
                this.id = getUrlParam("id");
                this.getData();
                //获取下拉菜单内容
              //  this.ClassificationofCourseware = getDicData('83');

            }

        });
    </script>
</body>

</html>